package cn.hy.controller;

import cn.hy.entity.User;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private RedisTemplate<String, User> redisTemplate;

    @PostMapping("add")
    public ResponseEntity<User> add(User user) {
        redisTemplate.opsForValue().set(String.valueOf(user.getId()), user);
        return ResponseEntity.ok(redisTemplate.opsForValue().get(String.valueOf(user.getId())));
    }

    @GetMapping("find/{userId}")
    public ResponseEntity<User> edit(@PathVariable("userId") String userId) {
        return ResponseEntity.ok(redisTemplate.opsForValue().get(userId));
    }

}